<template>
  <div class="login">
    <div class="login-one">
      <h2>后台管理系统</h2>
      <el-form
        :model="ruleForm"
        status-icon
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="用户名" prop="userName">
          <el-input type="text" v-model="ruleForm.userName"></el-input>
        </el-form-item>

        <el-form-item label="密码" prop="passWord">
          <el-input type="password" v-model="ruleForm.passWord"></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="submitForm">登录</el-button>
          <!-- <el-button @click="reset">重置</el-button> -->
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      ruleForm: {
        userName: "",
        passWord: "",
      },
    };
  },

  methods: {
    submitForm() {
      if(this.ruleForm.userName.length&&this.ruleForm.passWord.length){
        this.$http
        .post("/api/login", {
          userName: this.ruleForm.userName,
          passWord: this.ruleForm.passWord,
        })
        .then((res) => {
          console.log(res);
          if (res.data.code === 1) {
            window.localStorage.setItem("token", res.data.data.token);
            window.sessionStorage.setItem("auth", res.data.data.data[0].auth);
            this.$router.push("/Housing");
          }
        });
      }else{
        this.$message.error('不能为空')
      }
      
    },
  },
};
</script>

<style>
.login {
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-one {
  width: 700px;
  height: 500px;
  background: #fff;
  padding-right: 30px;
  padding-top: 50px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.login-one h2{
  height: 80px;
  line-height: 80px;
}
</style>